﻿<%@ Page Language="C#" MasterPageFile="~/grid.master" AutoEventWireup="true" CodeFile="ComboBox.aspx.cs" Inherits="Common_ComboBox" Title="Untitled Page" %>
<%@ Register Assembly="DevExpress.Web.ASPxTreeList.v8.3, Version=8.3.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
    Namespace="DevExpress.Web.ASPxTreeList" TagPrefix="dxwtl" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.3.Export, Version=8.3.2.0, Culture=neutral, PublicKeyToken=5377C8E3B72B4073"
    Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.v8.3, Version=8.3.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
    Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dxcp" %>
<%@ Register Assembly="DevExpress.Web.v8.3, Version=8.3.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
    Namespace="DevExpress.Web.ASPxPanel" TagPrefix="dxp" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.3, Version=8.3.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.3, Version=8.3.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>

<asp:Content ID="Content1" ContentPlaceHolderID="C2" Runat="Server">
    <script type="text/javascript" language="javascript">
    // 使用Dev提供的方案控制下拉列表联动
    function OnCompanyChanged(cmb) {
        comboDepartment.PerformCallback(cmb.GetValue().toString());
    }
    // 使用Dev提供的方案控制编辑界面中下拉列表联动
    function OnColumnCompanyChanged(cmb) {
        InfoGrid.GetEditor("DepartmentID").PerformCallback(cmb.GetValue().toString());
    }
    </script>
    <script type="text/javascript" language="javascript">
    
    // 使用PureDemo提供的下拉列表联动方案
    function OnParentComboChanged(mainCmb, mainType, subCmb, subType ) {
        var mainId = mainCmb.GetValue().toString();
        // 将mainId、mainType、subType通过Ajax调用，从后台获得子列表可用值
        var result = ajaxGetSubData ( mainId , mainType , subType );
        // 将结果设置到子列表中
        resultSet ( subCmb , result , false );
    }
    
    /**
     *				resultSet
     *
     * 说明: 将数据绑定到指定的
     * aDrop : 要绑定的下拉控件
     * aDatas : 返回的"name1,value1;name2,value2;..."格式字符串
     * aHasNone : 是否自动在最初位置加上“无”选项
     */		
    function resultSet ( combo , aDatas , aHasNone )
    {
	    // 防止提供了非下拉列表的绑定
        combo.ClearItems();

	    // 增加一个“无”选项
	    if ( aHasNone )
	    {
	        combo.AddItem ( "无" , "0" );
	    }
    	
	    // Handle "value1,name1;value2,name2;..." format strings
	    var lines = aDatas.split ( ";" ) ;
	    for ( var i = 0 ; i < lines.length ; i++ )
	    {
		    var line = lines[i] ;
		    if ( line.length > 0 )
		    {
			    if ( line.indexOf ( "," ) != -1 )
			    {
				    var params = line.split ( "," ) ;
				    combo.AddItem ( params[1] , params[0] );
			    }
		    }
	    }
    }

    function ajaxGetSubData ( mainId , mainType , subType )
    {
        var xmlHttp = getXmlHttpRequest();
        var param = "mainId="+mainId+"&mainType="+mainType+"&subType="+subType;
        xmlHttp.open("GET", "../Ajax/ComboData.aspx?"+param, false);
        //xmlHttp.open("GET", "http://localhost:11135/WebUI/Ajax/ComboData.aspx", false);
        xmlHttp.send(null);
        return xmlHttp.responseText;
    }
    
    function getXmlHttpRequest()
    {
        var xmlhttp=false;
        // JScript gives us Conditional compilation, we can cope with old IE versions.
        // and security blocked creation of the objects.
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	        try {
		        xmlhttp = new XMLHttpRequest();
	        } catch (e) {
		        xmlhttp=false;
	        }
        }
        if (!xmlhttp && window.createRequest) {
	        try {
		        xmlhttp = window.createRequest();
	        } catch (e) {
		        xmlhttp=false;
	        }
        }

        return xmlhttp;
    }
    
    </script>
    <dxcp:ASPxCallbackPanel ID="ajaxPanel" ClientInstanceName="ajaxPanel"
        LoadingPanelText="数据加载中…" OnCallback="ajaxPanel_Callback" runat="server" HideContentOnCallback="False">
        <PanelCollection>
            <dxp:PanelContent runat="server">
                <div class="queryLine">
                    <table cellpadding="0" cellspacing="0">
                        <tr>
                            <td valign="top">
                                <dxe:ASPxLabel ID="ASPxLabel3" runat="server" Text="Ajax Resolution:省份">
                                </dxe:ASPxLabel>
                            </td>
                            <td>
                                <dxe:ASPxComboBox ID="comboProvince" runat="server" DataSourceID="dsProvince" EnableIncrementalFiltering="True"
                                    EnableSynchronization="False" TextField="Name" ValueField="Id" ValueType="System.String">
                                    <ClientSideEvents SelectedIndexChanged="function(s, e) { OnParentComboChanged(s, 'Province_MDL', comboCity, 'City_MDL'); }" />
                                </dxe:ASPxComboBox>
                            </td>
                            <td valign="top">
                                <dxe:ASPxLabel ID="ASPxLabel6" runat="server" Text="城市">
                                </dxe:ASPxLabel>
                            </td>
                            <td>
                                <dxe:ASPxComboBox ID="comboCity" runat="server" ClientInstanceName="comboCity"
                                    DataSourceID="dsCity" EnableIncrementalFiltering="True" EnableSynchronization="False"
                                    TextField="Name" ValueField="Id" ValueType="System.String">
                                </dxe:ASPxComboBox>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="buttonLine">
                     <table cellpadding="0" cellspacing="0">
                        <tr>
                            <td valign="top">
                                <dxe:ASPxLabel ID="ASPxLabel4" runat="server" Text="Dev Resolution:公司">
                                </dxe:ASPxLabel>
                            </td>
                            <td>
                                <dxe:ASPxComboBox ID="comboCompany" runat="server" EnableIncrementalFiltering="True" 
                                    DataSourceID="dsCompany" TextField="CompanyName" ValueField="CompanyID" EnableSynchronization="False" ValueType="System.String">
                                    <ClientSideEvents SelectedIndexChanged="function(s, e) { OnCompanyChanged(s); }"></ClientSideEvents>
                                </dxe:ASPxComboBox>
                            </td>
                            <td valign="top">
                                <dxe:ASPxLabel ID="ASPxLabel5" runat="server" Text="部门">
                                </dxe:ASPxLabel>
                            </td>
                            <td>
                                <dxe:ASPxComboBox ID="comboDepartment" ClientInstanceName="comboDepartment" runat="server" EnableIncrementalFiltering="True" 
                                    DataSourceID="dsDepartment" TextField="Name" ValueField="Id" EnableSynchronization="False" OnCallback="comboDepartment_Callback" ValueType="System.String">
                                </dxe:ASPxComboBox>
                            </td>
                        </tr>
                    </table>
               </div>
                <div class="infoGrid">
                    <dxwgv:ASPxGridView ID="InfoGrid" ClientInstanceName="InfoGrid" 
                        DataSourceID = "dataSource"
                        KeyFieldName="ID" Width="100%" runat="server"
                        OnCustomCallback="InfoGrid_CustomCallback"
                        OnInitNewRow="InfoGrid_InitNewRow"
                        OnRowDeleting="InfoGrid_RowDeleting"
                        OnRowValidating="InfoGrid_RowValidating" 
                        OnPreRender="InfoGrid_PreRender" AutoGenerateColumns="False" OnRowInserting="InfoGrid_RowInserting" OnRowUpdating="InfoGrid_RowUpdating" OnCellEditorInitialize="InfoGrid_CellEditorInitialize"  >
                        <Columns>
                            <dxwgv:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" >
                                <HeaderTemplate>
                                    <input title="[选择/取消选择]本页所有行" onclick="InfoGrid.SelectAllRowsOnPage(this.checked);"
                                        style="vertical-align: middle;" id="chkPageSelectAll" type="checkbox" />
                                </HeaderTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                            </dxwgv:GridViewCommandColumn>
                            <dxwgv:GridViewDataComboBoxColumn FieldName="ProvinceID" VisibleIndex="1">
                                 <PropertiesComboBox TextField="Name"  ValueField="Id" DropDownStyle="DropDownList" EnableSynchronization="False" EnableIncrementalFiltering="True" DataSourceID="dsProvince" ValueType="System.String">
                                     <ClientSideEvents SelectedIndexChanged="function(s, e) { OnParentComboChanged(s, 'Province_MDL', cmbCity, 'City_MDL'); }"></ClientSideEvents>
                                 </PropertiesComboBox>
                            </dxwgv:GridViewDataComboBoxColumn>
                            <dxwgv:GridViewDataComboBoxColumn  FieldName="CityID" VisibleIndex="2" >
                                <PropertiesComboBox DataSourceID="dsCity" ClientInstanceName="cmbCity" EnableIncrementalFiltering="True" 
                                    TextField="Name" ValueField="ID" ValueType="System.String"   >
                                </PropertiesComboBox>
                            </dxwgv:GridViewDataComboBoxColumn>
                            <dxwgv:GridViewDataComboBoxColumn FieldName="CompanyID" VisibleIndex="3">
                                <PropertiesComboBox DataSourceID="dsCompany" DropDownStyle="DropDownList" EnableIncrementalFiltering="True"
                                    EnableSynchronization="False" TextField="CompanyName" ValueField="CompanyID" ValueType="System.String">
                                    <ClientSideEvents SelectedIndexChanged="function(s, e) { OnColumnCompanyChanged(s); }" />
                                </PropertiesComboBox>
                            </dxwgv:GridViewDataComboBoxColumn>
                            <dxwgv:GridViewDataComboBoxColumn FieldName="DepartmentID" VisibleIndex="4">
                                <PropertiesComboBox DataSourceID="dsDepartment" EnableIncrementalFiltering="True" TextField="Name"
                                    ValueField="ID" ValueType="System.String">
                                </PropertiesComboBox>
                            </dxwgv:GridViewDataComboBoxColumn>
                            <dxwgv:GridViewDataTextColumn FieldName="Name"  VisibleIndex="5" >
                            </dxwgv:GridViewDataTextColumn>
                            <dxwgv:GridViewCommandColumn Caption="操作" VisibleIndex="6" >
                                <EditButton Visible="True" ></EditButton>
                            </dxwgv:GridViewCommandColumn>
                        </Columns>
                   </dxwgv:ASPxGridView>
                </div>
            </dxp:PanelContent>
        </PanelCollection>
    </dxcp:ASPxCallbackPanel>
    <asp:ObjectDataSource ID="dataSource" runat="server" DataObjectTypeName="OT.Module.Model.Employee_MDL"
        TypeName="OT.Module.BLL.Employee_BLL" 
        OnSelecting="dataSource_Selecting" SelectMethod="Select" 
        OnObjectCreating="ds_ObjectCreating">
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="dsProvince" runat="server" DataObjectTypeName="OT.Module.Model.Province_MDL"
        OnObjectCreating="dsProvince_ObjectCreating" SelectMethod="Select" TypeName="OT.Module.BLL.Province_BLL">
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="dsCity" runat="server" DataObjectTypeName="OT.Module.Model.City_MDL"
        OnObjectCreating="dsCity_ObjectCreating" SelectMethod="Select"
        TypeName="OT.Module.BLL.City_BLL">
        <SelectParameters>
            <asp:Parameter Name="provinceId" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="dsCompany" runat="server" DataObjectTypeName="OT.Module.Model.Company_MDL"
        OnObjectCreating="dsCompany_ObjectCreating" SelectMethod="Select" TypeName="OT.Module.BLL.Company_BLL">
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="dsDepartment" runat="server" DataObjectTypeName="OT.Module.Model.Department_MDL"
        OnObjectCreating="dsDepartment_ObjectCreating" SelectMethod="Select" TypeName="OT.Module.BLL.Department_BLL">
        <SelectParameters>
            <asp:Parameter Name="companyId" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
</asp:Content>

